package com.itheima.d5_MultipleCast;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

/**
 *  1.创建发送人
 *  2.创建盘子
 *  DatagramPacket(byte[] buf, int length, InetAddress address, int port)
 *  3. 我想不停的发送
 */
public class Client {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket_sender = new DatagramSocket();
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("输入弹幕:");
            String msg = sc.nextLine();

            if ("exit".equals(msg)){
                System.out.println("离线了");
                socket_sender.close();
                sc.close();
                break;
            }

            byte[] bytes = msg.getBytes();
            DatagramPacket packet = new DatagramPacket(bytes,bytes.length,
                    InetAddress.getByName("224.0.0.1"),999);
            // 发送数据
            socket_sender.send(packet);
        }
        // 关闭
        //socket_sender.close();
    }

}
